{
  "name": "Case 77 - PR Manager - Brand Mention Tracker",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -688,
        -224
      ],
      "id": "6b40d214-e574-4d42-b699-9c49c6a1bd0f",
      "name": "Weekly Schedule - Monday 9 AM"
    },
    {
      "parameters": {
        "actorId": {
          "__rl": true,
          "value": "buIWk2uOUzTmcLsuB",
          "mode": "list",
          "cachedResultName": "Linkedin Post Search Scraper (No Cookies) (harvestapi/linkedin-post-search)",
          "cachedResultUrl": "https://console.apify.com/actors/buIWk2uOUzTmcLsuB/input"
        },
        "customBody": "{\n  \"authorUrls\": [\n    \"https://www.linkedin.com/in/tech-journalist-1\",\n    \"https://www.linkedin.com/in/industry-analyst-2\",\n    \"https://www.linkedin.com/company/techcrunch\",\n    \"https://www.linkedin.com/company/theverge\",\n    \"https://www.linkedin.com/company/wired\",\n    \"https://www.linkedin.com/in/thought-leader-1\",\n    \"https://www.linkedin.com/in/influencer-2\",\n    \"https://www.linkedin.com/company/competitor-company-1\",\n    \"https://www.linkedin.com/company/partner-company-1\"\n  ],\n  \"searchKeywords\": [\n    \"YourBrand\",\n    \"YourProduct\",\n    \"YourCEO\",\n    \"competitor to YourBrand\"\n  ],\n  \"maxPosts\": 50,\n  \"postedLimit\": \"week\",\n  \"scrapeComments\": false,\n  \"scrapeReactions\": false\n}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -496,
        -224
      ],
      "id": "78a45d8c-8fbd-471c-9490-677cb6b6941b",
      "name": "Scrape LinkedIn Brand Mentions",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -304,
        -224
      ],
      "id": "2c7ab61f-27e7-4956-8f3d-4b36ef7ac47e",
      "name": "Get Dataset Items",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Brand Mention Validation Expert.\n\nAnalyze LinkedIn posts to determine if they are genuine brand mentions worth tracking.\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"is_brand_mention\": \"yes|no\",\n  \"confidence\": 0.95,\n  \"reason\": \"brief explanation\"\n}\n\nCriteria for \"yes\" (genuine brand mention):\n✅ Direct mention of brand/product/company name\n✅ Discussion of brand's products or services\n✅ Comparison with brand (competitive analysis)\n✅ Review or experience with brand\n✅ Partnership or collaboration announcement involving brand\n✅ News article or media coverage about brand\n✅ CEO or leadership quoted or referenced\n✅ Customer testimonial or case study\n\nCriteria for \"no\" (NOT a brand mention):\n❌ Brand name used in unrelated context\n❌ Coincidental keyword match (e.g., \"apple\" the fruit vs Apple the company)\n❌ Self-promotion by brand's own official account (unless analyzing competitors)\n❌ Generic industry discussion without specific brand focus\n❌ Spam or promotional posts\n❌ Job postings mentioning brand casually\n❌ Comments/replies (not original posts)\n\nRules:\n1. confidence: 0-1 scale (0.9+ for very clear brand mentions)\n2. reason: 1 sentence explaining the decision\n3. Be strict - require actual substantive brand discussion\n4. Return ONLY the JSON object, no explanations"
            },
            {
              "content": "=Analyze this LinkedIn post to determine if it's a genuine brand mention:\n\nAuthor: {{ $json.author.name }}\nPost Date: {{ $json.postedAt.date }}\nPost Content: {{ $json.content }}\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        -64,
        -224
      ],
      "id": "b02c7f46-a139-4cea-bb03-3f002a4a1c5a",
      "name": "AI Validation Filter",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        288,
        -224
      ],
      "id": "abd1ba93-4355-41e8-b371-25af7cbd41d2",
      "name": "Parse AI Validation"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "is_brand_mention",
              "name": "is_brand_mention",
              "value": "={{ $json.is_brand_mention }}",
              "type": "string"
            },
            {
              "id": "confidence",
              "name": "confidence",
              "value": "={{ $json.confidence }}",
              "type": "number"
            },
            {
              "id": "reason",
              "name": "reason",
              "value": "={{ $json.reason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        480,
        -224
      ],
      "id": "1348d52c-bde1-4932-b1f1-b1343b5a5b1c",
      "name": "Edit Fields - Validation"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "condition-001",
              "leftValue": "={{ $json.is_brand_mention }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        672,
        -224
      ],
      "id": "64fcfc22-39e7-40f0-b0b2-3c54d367c601",
      "name": "Filter Only Brand Mentions"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Brand Mention Intelligence Analyst.\n\nExtract structured brand mention information from LinkedIn posts.\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"mention_type\": \"Product|Company|Leadership|Partnership|Criticism|Review|News|Comparison\",\n  \"context\": \"What was being discussed when brand was mentioned (max 150 chars)\",\n  \"tone\": \"Positive|Negative|Neutral|Mixed\",\n  \"reach_indicator\": \"High|Medium|Low - based on author's follower count or engagement\",\n  \"key_claims\": \"Main points made about the brand (max 200 chars)\",\n  \"response_needed\": \"Yes|No - Does this require brand response?\",\n  \"opportunity_type\": \"Partnership|Testimonial|Case Study|Crisis Management|Media Outreach|None\",\n  \"journalist_flag\": \"Yes|No - Is author from media/press?\"\n}\n\nExtraction Rules:\n1. mention_type: Categorize the primary reason for mention\n2. context: Brief summary of discussion topic\n3. tone: Overall sentiment toward brand\n4. reach_indicator: Assess based on engagement metrics (High = 1000+ engagement, Medium = 100-999, Low = <100)\n5. key_claims: Extract what they said about brand\n6. response_needed: Yes if criticism, question, or opportunity requiring action\n7. opportunity_type: Identify PR/marketing opportunity if present\n8. journalist_flag: Yes if author is journalist/media (check profile info)\n\nReturn ONLY the JSON object, no explanations."
            },
            {
              "content": "=Extract brand mention intelligence from this LinkedIn post:\n\nAuthor: {{ $('Get Dataset Items').item.json.author.name }}\nAuthor Info: {{ $('Get Dataset Items').item.json.author.info }}\nPost Date: {{ $('Get Dataset Items').item.json.postedAt.date }}\nPost Content: {{ $('Get Dataset Items').item.json.content }}\nEngagement: {{ $('Get Dataset Items').item.json.engagement.likes }} likes, {{ $('Get Dataset Items').item.json.engagement.comments }} comments\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        832,
        -224
      ],
      "id": "d261a291-280e-47b5-92e0-41f170be4366",
      "name": "AI Extract Brand Intelligence",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1168,
        -224
      ],
      "id": "3197ed65-55f1-4415-a3b0-7285ad48ae4c",
      "name": "Parse AI Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "timestamp",
              "name": "analysis_timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "author_name",
              "name": "author_name",
              "value": "={{ $('Get Dataset Items').item.json.author?.name || 'unknown' }}",
              "type": "string"
            },
            {
              "id": "author_profile",
              "name": "author_profile",
              "value": "={{ $('Get Dataset Items').item.json.author?.linkedinUrl || '' }}",
              "type": "string"
            },
            {
              "id": "author_info",
              "name": "author_info",
              "value": "={{ $('Get Dataset Items').item.json.author?.info || '' }}",
              "type": "string"
            },
            {
              "id": "mention_type",
              "name": "mention_type",
              "value": "={{ $json.mention_type }}",
              "type": "string"
            },
            {
              "id": "context",
              "name": "context",
              "value": "={{ $json.context }}",
              "type": "string"
            },
            {
              "id": "tone",
              "name": "tone",
              "value": "={{ $json.tone }}",
              "type": "string"
            },
            {
              "id": "reach",
              "name": "reach_indicator",
              "value": "={{ $json.reach_indicator }}",
              "type": "string"
            },
            {
              "id": "claims",
              "name": "key_claims",
              "value": "={{ $json.key_claims }}",
              "type": "string"
            },
            {
              "id": "response",
              "name": "response_needed",
              "value": "={{ $json.response_needed }}",
              "type": "string"
            },
            {
              "id": "opportunity",
              "name": "opportunity_type",
              "value": "={{ $json.opportunity_type }}",
              "type": "string"
            },
            {
              "id": "journalist",
              "name": "journalist_flag",
              "value": "={{ $json.journalist_flag }}",
              "type": "string"
            },
            {
              "id": "post_content",
              "name": "post_content",
              "value": "={{ $('Get Dataset Items').item.json.content || '' }}",
              "type": "string"
            },
            {
              "id": "post_date",
              "name": "post_date",
              "value": "={{ $('Get Dataset Items').item.json.postedAt?.date || '' }}",
              "type": "string"
            },
            {
              "id": "post_url",
              "name": "post_url",
              "value": "={{ $('Get Dataset Items').item.json.linkedinUrl || '' }}",
              "type": "string"
            },
            {
              "id": "likes",
              "name": "likes_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.likes || 0 }}",
              "type": "number"
            },
            {
              "id": "comments",
              "name": "comments_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.comments || 0 }}",
              "type": "number"
            },
            {
              "id": "shares",
              "name": "shares_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.shares || 0 }}",
              "type": "number"
            },
            {
              "id": "total_engagement",
              "name": "engagement_total",
              "value": "={{ ($('Get Dataset Items').item.json.engagement?.likes || 0) + ($('Get Dataset Items').item.json.engagement?.comments || 0) + ($('Get Dataset Items').item.json.engagement?.shares || 0) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1344,
        -224
      ],
      "id": "21535397-ba6a-4040-9ad8-23b0bf1b232b",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1rTsn-WNgXXqtJmrPp-pnnciYqqLgDntp7C8rCd83hGU",
          "mode": "list",
          "cachedResultName": "Case 77 - Brand Mention Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rTsn-WNgXXqtJmrPp-pnnciYqqLgDntp7C8rCd83hGU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rTsn-WNgXXqtJmrPp-pnnciYqqLgDntp7C8rCd83hGU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Analysis_Date": "={{ $json.analysis_timestamp }}",
            "Author_Name": "={{ $json.author_name }}",
            "Author_Info": "={{ $json.author_info }}",
            "Mention_Type": "={{ $json.mention_type }}",
            "Context": "={{ $json.context }}",
            "Tone": "={{ $json.tone }}",
            "Reach_Indicator": "={{ $json.reach_indicator }}",
            "Key_Claims": "={{ $json.key_claims }}",
            "Response_Needed": "={{ $json.response_needed }}",
            "Opportunity_Type": "={{ $json.opportunity_type }}",
            "Journalist_Flag": "={{ $json.journalist_flag }}",
            "Post_Date": "={{ $json.post_date }}",
            "Likes": "={{ $json.likes_count }}",
            "Comments": "={{ $json.comments_count }}",
            "Shares": "={{ $json.shares_count }}",
            "Total_Engagement": "={{ $json.engagement_total }}",
            "Post_URL": "={{ $json.post_url }}",
            "Post_Content": "={{ $json.post_content }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Analysis_Date",
              "displayName": "Analysis_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Author_Name",
              "displayName": "Author_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Author_Info",
              "displayName": "Author_Info",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Mention_Type",
              "displayName": "Mention_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Context",
              "displayName": "Context",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tone",
              "displayName": "Tone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Reach_Indicator",
              "displayName": "Reach_Indicator",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Key_Claims",
              "displayName": "Key_Claims",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Response_Needed",
              "displayName": "Response_Needed",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Opportunity_Type",
              "displayName": "Opportunity_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Journalist_Flag",
              "displayName": "Journalist_Flag",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Date",
              "displayName": "Post_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Likes",
              "displayName": "Likes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Comments",
              "displayName": "Comments",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Shares",
              "displayName": "Shares",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Total_Engagement",
              "displayName": "Total_Engagement",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_URL",
              "displayName": "Post_URL",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Content",
              "displayName": "Post_Content",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1536,
        -224
      ],
      "id": "9e7f9a3d-a777-4dd2-8dec-5fe62c54d431",
      "name": "Log to Google Sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Aggregate all items from Google Sheets into email-ready summary\nconst allItems = $input.all();\n\n// Count by mention type\nconst mentionTypeCounts = {};\nallItems.forEach(item => {\n  const type = item.json.Mention_Type || 'Other';\n  mentionTypeCounts[type] = (mentionTypeCounts[type] || 0) + 1;\n});\n\n// Count by tone\nconst toneCounts = {};\nallItems.forEach(item => {\n  const tone = item.json.Tone || 'Neutral';\n  toneCounts[tone] = (toneCounts[tone] || 0) + 1;\n});\n\n// Count requiring response\nconst responseNeeded = allItems.filter(item => \n  item.json.Response_Needed === 'Yes'\n).length;\n\n// Count journalists\nconst journalistMentions = allItems.filter(item => \n  item.json.Journalist_Flag === 'Yes'\n).length;\n\n// Count by opportunity type\nconst opportunityCounts = {};\nallItems.forEach(item => {\n  const opp = item.json.Opportunity_Type || 'None';\n  if (opp !== 'None') {\n    opportunityCounts[opp] = (opportunityCounts[opp] || 0) + 1;\n  }\n});\n\n// High reach mentions\nconst highReachMentions = allItems.filter(item => \n  item.json.Reach_Indicator === 'High'\n);\n\n// Negative mentions requiring attention\nconst negativeMentions = allItems.filter(item => \n  item.json.Tone === 'Negative' || item.json.Tone === 'Mixed'\n);\n\n// Build HTML table rows\nconst tableRows = allItems.map(item => {\n  const data = item.json;\n  const toneColor = data.Tone === 'Positive' ? '#28a745' : \n                    data.Tone === 'Negative' ? '#dc3545' : \n                    data.Tone === 'Mixed' ? '#ffc107' : '#6c757d';\n  \n  return `\n    <tr>\n      <td>${data.Author_Name || 'N/A'}</td>\n      <td>${data.Mention_Type || 'N/A'}</td>\n      <td><span style=\"color: ${toneColor}; font-weight: bold;\">${data.Tone || 'N/A'}</span></td>\n      <td>${data.Reach_Indicator || 'N/A'}</td>\n      <td>${data.Response_Needed || 'N/A'}</td>\n      <td>${data.Opportunity_Type || 'N/A'}</td>\n      <td><a href=\"${data.Post_URL || '#'}\">View</a></td>\n    </tr>\n  `;\n}).join('');\n\n// Return single aggregated item\nreturn {\n  json: {\n    week_start: new Date(Date.now() - 7*24*60*60*1000).toISOString().split('T')[0],\n    week_end: new Date().toISOString().split('T')[0],\n    total_mentions: allItems.length,\n    mention_type_breakdown: Object.entries(mentionTypeCounts),\n    tone_breakdown: Object.entries(toneCounts),\n    response_needed_count: responseNeeded,\n    journalist_mentions_count: journalistMentions,\n    opportunity_breakdown: Object.entries(opportunityCounts),\n    high_reach_count: highReachMentions.length,\n    negative_mentions_count: negativeMentions.length,\n    table_rows: tableRows,\n    all_mentions: allItems.map(item => item.json)\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1728,
        -224
      ],
      "id": "85d53432-ac10-4c1f-bac3-2e5649c72671",
      "name": "Aggregate Weekly Summary"
    },
    {
      "parameters": {
        "sendTo": "pr-team@yourcompany.com",
        "subject": "=📊 Weekly Brand Mention Report: {{ $json.week_start }} to {{ $json.week_end }}",
        "message": "=WEEKLY BRAND MENTION INTELLIGENCE REPORT\n================================================\nReport Period: {{ $json.week_start }} to {{ $json.week_end }}\n\nOVERVIEW:\nTotal Brand Mentions: {{ $json.total_mentions }}\nRequire Response: {{ $json.response_needed_count }}\nJournalist Mentions: {{ $json.journalist_mentions_count }}\nHigh Reach Mentions: {{ $json.high_reach_count }}\nNegative/Mixed Sentiment: {{ $json.negative_mentions_count }}\n\nMENTION TYPE BREAKDOWN:\n{{ $json.mention_type_breakdown.map(([type, count]) => type + ': ' + count).join('\\n') }}\n\nSENTIMENT ANALYSIS:\n{{ $json.tone_breakdown.map(([tone, count]) => tone + ': ' + count).join('\\n') }}\n\nOPPORTUNITIES IDENTIFIED:\n{{ $json.opportunity_breakdown.length > 0 ? $json.opportunity_breakdown.map(([opp, count]) => opp + ': ' + count).join('\\n') : 'No opportunities identified' }}\n\nACTION ITEMS:\n- {{ $json.response_needed_count }} mentions require response\n- {{ $json.journalist_mentions_count }} journalist mentions to review\n- {{ $json.negative_mentions_count }} negative mentions to address\n\nFull mention details in Google Sheets.\n\nGenerated: {{ new Date().toLocaleDateString() }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1920,
        -224
      ],
      "id": "37bacdf7-e332-43ce-b5a7-071f83a58b1c",
      "name": "Send Weekly Summary Email",
      "webhookId": "0a249d50-9bb6-4273-872f-0c6f7465a148",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Weekly Schedule - Monday 9 AM": {
      "main": [
        [
          {
            "node": "Scrape LinkedIn Brand Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape LinkedIn Brand Mentions": {
      "main": [
        [
          {
            "node": "Get Dataset Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Dataset Items": {
      "main": [
        [
          {
            "node": "AI Validation Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Validation Filter": {
      "main": [
        [
          {
            "node": "Parse AI Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Validation": {
      "main": [
        [
          {
            "node": "Edit Fields - Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields - Validation": {
      "main": [
        [
          {
            "node": "Filter Only Brand Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Only Brand Mentions": {
      "main": [
        [
          {
            "node": "AI Extract Brand Intelligence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Extract Brand Intelligence": {
      "main": [
        [
          {
            "node": "Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Log to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheet": {
      "main": [
        [
          {
            "node": "Aggregate Weekly Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Weekly Summary": {
      "main": [
        [
          {
            "node": "Send Weekly Summary Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c5f2d9f6-d5e4-4707-9a82-61164e9d3d82",
  "meta": {
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "9sz12THzroO8a1cS",
  "tags": []
}